/*
 * Created by JFormDesigner on Wed Jun 02 09:51:10 CST 2010
 */

package edu.thu.thss.yxy.gui;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;

import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;

/**
 * 
 * JAIN-SIP Audio/Video phone application
 * 
 * @author Andy Gao
 */
public class MainFrame extends JFrame {
	public MainFrame() {
		initComponents();

		Toolkit toolkit = Toolkit.getDefaultToolkit();
		pack();
		int x = (toolkit.getScreenSize().width - getWidth()) / 2;
		int y = (toolkit.getScreenSize().height - getHeight()) / 2;
		setLocation(x, y);
	}

	private void initComponents() {
		// JFormDesigner - Component initialization - DO NOT MODIFY
		// //GEN-BEGIN:initComponents
		// Generated using JFormDesigner Open Source Project license - unknown
		menuBar = new JMenuBar();
		optionMenu = new JMenu();
		helpMenu = new JMenu();
		configItem = new JMenuItem();
		exitItem = new JMenuItem();
		aboutItem = new JMenuItem();

		splitPane = new JSplitPane();
		videoPanel = new JPanel();

		controlPanel = new JPanel();

		dialPanel = new JPanel();
		contactBox = new JComboBox();
		dialButton = new JButton();

		peersTable = new JTable(30, 3);
		peersScrollPane = new JScrollPane();

		callBtnPanel = new JPanel();
		answerBtn = new JButton();
		hangupBtn = new JButton();

		statusPanel = new JPanel();
		registrationLabel = new JLabel();
		registrationAddressLabel = new JLabel();

		// ======== this ========
		Container contentPane = getContentPane();
		contentPane.setLayout(new BorderLayout());

		// ======== menuBar ========
		{

			// ======== optionMenu ========
			{
				optionMenu.setText("Options");

				// ---- configItem ----
				configItem.setText("Configuration");
				optionMenu.add(configItem);

				// ---- exitItem ----
				exitItem.setText("Exit");
				optionMenu.add(exitItem);
			}
			// ========helpMenu==========
			{
				helpMenu.setText("Help");

				// ---- configItem ----
				aboutItem.setText("About...");
				aboutItem.addActionListener(new ActionListener(){
					public void actionPerformed(ActionEvent evt)
			        {
			            JOptionPane.showMessageDialog(
			                null,
			                "Multiedia Course Project\n" +
			                "Tsinghua University\n" +
			                "Author: Gao An\n" +
			                "2009212628\n" +
			                "e-mail: gaoan0128@gmail.com\n" +
			                "Author: Fu Cheng\n"
			                );
			        }
				});
				helpMenu.add(aboutItem);
			}
			menuBar.add(optionMenu);
			menuBar.add(helpMenu);
		}
		setJMenuBar(menuBar);
		setPreferredSize(new Dimension(300, 600));
		setSize(300, 600);
//		setResizable(false);
		setState(Frame.NORMAL);
		setTitle("GoPhone---Multimedia Project");

		// ======== splitPane ========
		{
			splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);

			// ======== panel ========
			{
				videoPanel.setLayout(new BoxLayout(videoPanel, BoxLayout.X_AXIS));
				videoPanel.setBorder(BorderFactory
						.createEmptyBorder(5, 5, 5, 5));
			}
			splitPane.setTopComponent(videoPanel);

			// ======== control panel ========
			{
				controlPanel.setLayout(new BorderLayout(10, 0));
				// ============dialPanel=============
				dialButton.setEnabled(false);
				dialButton.setMnemonic('D');
				dialButton.setText("Dial");
				contactBox.setActionMap(null);
				contactBox.setEditable(true);
				contactBox.addItem("");
				contactBox.setSelectedIndex(0);
				dialPanel.setLayout(new BorderLayout(10, 0));
				dialPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
				dialPanel.add(dialButton, BorderLayout.EAST);
				dialPanel.add(contactBox, BorderLayout.CENTER);
				controlPanel.add(dialPanel, BorderLayout.NORTH);

				peersScrollPane.setViewportView(peersTable);
				controlPanel.add(peersScrollPane, BorderLayout.CENTER);

				answerBtn.setEnabled(false);
				answerBtn.setMnemonic('A');
				answerBtn.setText("Answer");
				hangupBtn.setEnabled(false);
				hangupBtn.setMnemonic('H');
				hangupBtn.setText("Hangup");
				callBtnPanel.setLayout(new GridLayout(1, 2, 10, 10));
				callBtnPanel.add(answerBtn);
				callBtnPanel.add(hangupBtn);
				controlPanel.add(callBtnPanel, BorderLayout.SOUTH);
			}
			splitPane.setBottomComponent(controlPanel);
			splitPane.setDividerLocation(300);
		}

		// =================status Panel===============
		registrationLabel.setText("Not Registered");
		registrationAddressLabel.addMouseListener(new MouseAdapter() {
			public void mouseEntered(MouseEvent e) {
				registrationAddressLabel.setToolTipText(
						registrationAddressLabel.getText());
			}
		});
		statusPanel.setLayout(new BorderLayout());
		Border statusBorder = BorderFactory.createCompoundBorder(
				new EtchedBorder(EtchedBorder.RAISED, Color.white, new Color(
						156, 156, 158)), BorderFactory.createEmptyBorder(5, 5,
						5, 5));
		statusPanel.setBorder(statusBorder);
		statusPanel.setMaximumSize(new Dimension(32767, 32767));
		statusPanel.add(registrationLabel, BorderLayout.WEST);
		statusPanel.add(registrationAddressLabel, BorderLayout.CENTER);

		contentPane.add(splitPane, BorderLayout.CENTER);
		contentPane.add(statusPanel, BorderLayout.SOUTH);
		pack();
		setLocationRelativeTo(getOwner());
		// JFormDesigner - End of component initialization
		// //GEN-END:initComponents
	}

	protected void processWindowEvent(WindowEvent evt) {
		super.processWindowEvent(evt);
		if (evt.getID() == WindowEvent.WINDOW_CLOSING)
			System.exit(0);
	}

	public void showUp() {
		setExtendedState(Frame.NORMAL);
		setVisible(true);
		toFront();
	}

	public JButton getDialButton() {
		return dialButton;
	}

	public JButton getAnswerBtn() {
		return answerBtn;
	}

	public JButton getHangupBtn() {
		return hangupBtn;
	}

	public JComboBox getContactBox() {
		return contactBox;
	}

	public JTable getPeersTable() {
		return peersTable;
	}
	
	public JLabel getRegistrationLabel() {
		return registrationLabel;
	}

	public JLabel getRegistrationAddressLabel() {
		return registrationAddressLabel;
	}
	
	public JPanel getVideoPanel() {
		return videoPanel;
	}

	public JMenuItem getConfigItem() {
		return configItem;
	}

	public JMenuItem getExitItem() {
		return exitItem;
	}
	
	// JFormDesigner - Variables declaration - DO NOT MODIFY
	// //GEN-BEGIN:variables
	// Generated using JFormDesigner Open Source Project license - unknown
	private JMenuBar menuBar;
	private JMenu optionMenu;
	private JMenuItem configItem;
	private JMenuItem exitItem;
	private JMenu helpMenu;
	private JMenuItem aboutItem;

	private JSplitPane splitPane;
	private JPanel videoPanel;

	private JPanel controlPanel;

	private JPanel dialPanel;
	private JComboBox contactBox;
	private JButton dialButton;

	private JTable peersTable;
	private JScrollPane peersScrollPane;

	private JPanel callBtnPanel;
	private JButton answerBtn;
	private JButton hangupBtn;

	private JPanel statusPanel;
	private JLabel registrationLabel;
	private JLabel registrationAddressLabel;
	// JFormDesigner - End of variables declaration //GEN-END:variables
}
